package com.st.service.impl;

import com.st.dao.IUserDao;
import com.st.dao.impl.UserDaoImpl;
import com.st.entity.User;
import com.st.service.IUserService;

public class UserServiceImpl implements IUserService{

	private IUserDao userDao = new UserDaoImpl();
	
	@Override
	public User login(User user) {
		return userDao.select(user);
	}

	@Override
	public int modifyPwd(User user, String oldpassword, String newpassword, String newpassword2) {
		// 1. 判断旧密码是否正确
		if (!user.getPassword().equals(oldpassword)) {
			// 旧密码不正确
			return -2;
		}
		
		// 2. 两次新密码一致
		if (!newpassword.equals(newpassword2)) {
			// 两次密码不一致
			return -3;
		}
		
		// 3. 修改之
		return userDao.update(user.getId(), newpassword);
	}

	@Override
	public int addPhoto(Integer id, String photo) {
		return userDao.updatePhoto(id, photo);
	}

}
